const readline = require("readline");

console.log("请按提示依次输入信息：");
console.log("1) 姓名:");
console.log("2) 邮箱:");
console.log("3) QQ 号:");
console.log("4) 手机号码:");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

const user = {
    name: "",
    email: "",
    qq: "",
    phone: ""
};

const questions = [
    { key: "name", prompt: "姓名: " },
    { key: "email", prompt: "邮箱: " },
    { key: "qq", prompt: "QQ 号: " },
    { key: "phone", prompt: "手机号码: " }
];

let index = 0;

function askNext() {
    if (index >= questions.length) {
        rl.close();
        return;
    }
    const { key, prompt } = questions[index];
    rl.question(prompt, (answer) => {
        user[key] = answer.trim();
        index += 1;
        askNext();
    });
}

rl.on("close", () => {
    console.log("输入结束，信息如下：");
    console.log("%j", user);
});

askNext();